#pragma once
#include "Texture.h"
#include <memory>
#include <unordered_map>
#include <vector>
namespace Umikaze::Core {

struct ColorAttachmentInfo {
  ColorFormat _format;
  uint32_t _location;
};

class RenderTarget {
private:
  RenderTarget(int width, int height) : _width(width), _height(height) {}

public:
  RenderTarget &operator=(const RenderTarget &) = delete;
  RenderTarget(const RenderTarget &) = delete;

  RenderTarget(int width, int height,
               const std::vector<ColorAttachmentInfo> &colorAttachmentInfos);

  RenderTarget(int width, int height,
               const std::vector<ColorAttachmentInfo> &colorAttachmentInfos,
               DepthStencilFormat depthStencilFormat);

  RenderTarget(int width, int height, const ColorAttachmentInfo &info,
               DepthStencilFormat depthStencilFormat);

  RenderTarget(const std::shared_ptr<RenderTexture> &targetTexture,
               bool isDepth = false);

  RenderTarget(const std::shared_ptr<RenderTexture> &targetTexture,
               const std::shared_ptr<RenderTexture> &depthTexture);

  void setTargetColorTexture(const std::shared_ptr<RenderTexture> &colorTexture,
                             uint32_t location);

  void
  setTargetDepthTexture(const std::shared_ptr<RenderTexture> &depthTexture);

  void bind();

  void setSize(int width, int height);

  int _width = 0, _height = 0;

private:
  void addAttachment();

  uint32_t _fbo = 0;
  std::unordered_map<uint32_t, std::shared_ptr<RenderTexture>>
      _colorAttachments;
  bool _colorNeedUpdate = true;
  std::shared_ptr<RenderTexture> _depthAttachment;
  bool _depthNeedUpdate = true;
};

} // namespace Umikaze::Core